<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.hwhp.entity.*"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<html>
	<head>
		<title>权限分配</title>
		<LINK href="<%=basePath%>css/milkwhite.css" type=TEXT/CSS
			rel=StyleSheet></LINK>
		<LINK href="<%=basePath%>css/htmilkwhite.css" type=TEXT/CSS
			rel=StyleSheet></LINK>
		<LINK href="<%=basePath%>js/tree/dtree/dtree.css" type=text/css
			rel=StyleSheet>
		<base target="_self" >
		<SCRIPT src="<%=basePath%>js/tree/dtree/dtree.js" type=text/javascript></SCRIPT>
	</head>
	<%
	  List<Role> usedlist=(List<Role>)request.getAttribute("usedlist");
	  List<Role> unuselist=(List<Role>)request.getAttribute("unuselist");
	  List<YzUser> userlist=(List<YzUser>)request.getAttribute("userlist");
	  String success=(String)request.getAttribute("success");
	%>
	<body style="MARGIN: 0px;" id="body" onload="init()">
		<form name="fm1" action="/chis/manager/role!distributeRoleSave.action" method="post">
			<TABLE cellSpacing=10 width="100%">
				<TBODY>
					<tr>
						<td class=contenttab1 height="26px">
							当前操作：权限分配
						</td>
					</tr>
					<TR>
						<TD class=contenttab1 vAlign=top>
							<TABLE cellSpacing=2 cellPadding=0 width="100%" border=0>
								<TBODY>
									<TR>
									    <TD class=contenttab2 width="40%">
											授权人员
										</TD>
										<TD class=contenttab2 width="40%">
											目前权限
										</TD>
										<TD width="20%" rowspan="2" align="center">
										       <table border='0' cellpadding='2' cellspacing='0' id="buttonprcess" align="center">
								                  <tr height="20">
									                <td style='background-image:url(<%=basePath%>images/button/w_buttonmiddle1.gif);cursor: hand;' onclick="leftProcess()">
										               <<
									                </td>
								                  </tr>
								                  <tr height="20">
								                     <td>
								                     &nbsp;
								                     </td>
								                  </tr>
								                  <tr height="20">
									                <td style='background-image:url(<%=basePath%>images/button/w_buttonmiddle1.gif);cursor: hand;' onclick="rightProcess()">
										               >>
									                </td>
								                  </tr>
							                   </table>
										</TD>
										<TD class=contenttab2 width="40%">
											可用权限
										</TD>
									</TR>
									<TR>
									    <TD class=contenttab1>
										   <select size="8" id="userlist" name="userlist" style="width:100%">
										    <%
										      for(YzUser seluser:userlist){
										    %>
										     <option value="<%=seluser.getUserId() %>"><%=seluser.getUserName() %></option>
										    <%
										    }
										     %>
										   </select>
										</TD>
										<TD class=contenttab1>
										   <select size="8" id="usedlist" name="usedlist" style="width:100%">
										    <%
										      for(Role usedRole:usedlist){
										    %>
										     <option value="<%=usedRole.getId() %>"><%=usedRole.getRolename() %></option>
										    <%
										    }
										     %>
										   </select>
										</TD>
										<TD class=contenttab1>
										   <select size="8" id="unuselist" name="unuselist" style="width:100%">
										    <%
										      for(Role unuseRole:unuselist){
										    %>
										    <option value="<%=unuseRole.getId() %>"><%=unuseRole.getRolename() %></option>
										    <%
										    }
										     %>
										   </select>
										</TD>
									</TR>
								</TBODY>
							</TABLE>
						</TD>
					</TR>
					<tr height="40">
						<td align="center">
							<table border='0' cellpadding='2' cellspacing='0' id="buttonprcess">
								<tr height="20">
									<td style='background-image:url(<%=basePath%>images/button/w_buttonrleft1.gif);width:6px;'></td>
									<td style='background-image:url(<%=basePath%>images/button/w_buttonmiddle1.gif);cursor: hand;' onclick="saveProcess()">
										保存
									</td>
									<td style='background-image:url(<%=basePath%>images/button/w_buttonright1.gif);width:6px;'></td>
									<td>
										&nbsp;
									</td>
									<td style='background-image:url(<%=basePath%>images/button/w_buttonrleft1.gif);width:6px;'></td>
									<td style='background-image:url(<%=basePath%>images/button/w_buttonmiddle1.gif);cursor: hand;' onclick="cancleProcess()">
										取消
									</td>
									<td style='background-image:url(<%=basePath%>images/button/w_buttonright1.gif);width:6px;'></td>
								</tr>
							</table>
						</td>
					</tr>
				</TBODY>
			</TABLE>
			<input type="hidden" name="useridSet" id="useridSet"  value=""> 
			<input type="hidden" name="unroleidSet" id="unroleidSet"  value=""> 
			<input type="hidden" name="roleidSet" id="roleidSet"  value=""> 
			<input type="hidden" name="success" id="success"  value="<%=success%>"> 
		</form>
	</body>
</html>
	<script type=text/javascript>
	function init(){
	  var success=document.getElementById("success").value
	  if(success=='true'){
	    alert("权限配置成功！");
	  }
	  if(success=='false'){
	    alert("权限配置失败！");
	  }
	}
	//左移动
	function leftProcess(){
	     var rightObj=document.getElementById("unuselist");
	     var leftObj=document.getElementById("usedlist");
	     var rightSelectedIndex=rightObj.selectedIndex;
	     if(rightSelectedIndex=='-1'){
	       alert("请选择需要添加的角色");
	       return false;
	     }else{
	     var processObj =document.createElement("OPTION"); 
			 processObj.text = rightObj.item(rightSelectedIndex).text;
			 processObj.value = rightObj.item(rightSelectedIndex).value;
	         leftObj.add(processObj);
	         rightObj.remove(rightSelectedIndex);
	     }
	}
	//右移动
	function rightProcess(){
	     var rightObj=document.getElementById("unuselist");
	     var leftObj=document.getElementById("usedlist");
	     var leftSelectedIndex=leftObj.selectedIndex;
	     if(leftSelectedIndex=='-1'){
	       alert("请选择需要取消的角色");
	       return false;
	     }else{
	     var processObj =document.createElement("OPTION"); 
			 processObj.text = leftObj.item(leftSelectedIndex).text;
			 processObj.value = leftObj.item(leftSelectedIndex).value;
	         rightObj.add(processObj);
	         leftObj.remove(leftSelectedIndex);
	     }
	}
	//保存操作
	function saveProcess(){
	    var leftObj=document.getElementById("usedlist");
	    var length=leftObj.length;
	    var idSet='';
	    for(var i=0;i<length;i++){
	     idSet = idSet+",'"+leftObj.item(i).value+"'";
	    }
	    if(idSet!=''){
	    idSet=idSet.substring(1);
	    }
	    
	    var userListObj=document.getElementById("userlist");
	    var userlength=userListObj.length;
	    var useridSet='';
	    for(var i=0;i<userlength;i++){
	     useridSet = useridSet+",'"+userListObj.item(i).value+"'";
	    }
	    if(useridSet!=''){
	       useridSet=useridSet.substring(1);
	    }
	    
	    var rightObj=document.getElementById("unuselist");
	    var rightlength=rightObj.length;
	    var unroleidSet='';
	    for(var i=0;i<rightlength;i++){
	     unroleidSet = unroleidSet+",'"+rightObj.item(i).value+"'";
	    }
	    if(unroleidSet!=''){
	       unroleidSet=unroleidSet.substring(1);
	    }
	    
	    document.getElementById("roleidSet").value=idSet;
	    document.getElementById("useridSet").value=useridSet;
	    document.getElementById("unroleidSet").value=unroleidSet;
	    fm1.submit();
	}
	function cancleProcess(){
	     var success=document.getElementById("success").value;
	     window.returnValue=success;
		 window.close();
	}
	</script>
